//
//  SuggestUsViewController.m
//  NiuBanJin
//
//  Created by zf on 15/10/12.
//  Copyright © 2015年 zzjr. All rights reserved.
//

#import "SuggestUsViewController.h"
#import "IDCardAuthenticationViewController.h"
#import "MoreSettingsViewController.h"
@interface SuggestUsViewController ()<UITextViewDelegate , UIAlertViewDelegate>
@property (nonatomic , strong) UITextView *field_suggext;
@end

@implementation SuggestUsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"意见反馈";
    self.view.backgroundColor = BASECOLOR;
    
    self.field_suggext = [[UITextView alloc]init];
    self.field_suggext.delegate = self;
    self.field_suggext.tag = 400;
    //    self.field_suggext.contentVerticalAlignment = UIControlContentHorizontalAlignmentFill;
    //    self.field_suggext.contentHorizontalAlignment = UIControlContentVerticalAlignmentTop;
    _field_suggext.font = [UIFont systemFontOfSize:15];
    //    [self.field_suggext addTarget:self action:@selector(fieldAcrion:) forControlEvents:UIControlEventAllTouchEvents];
    self.field_suggext.backgroundColor = [UIColor whiteColor];
    
    UILabel *label_phone = [[UILabel alloc]init];
    label_phone.adjustsFontSizeToFitWidth = YES;
    label_phone.textAlignment = NSTextAlignmentCenter;
    label_phone.textColor = [UsefulUtil colorWithHexString:@"#989898"];
    label_phone.font = [UIFont systemFontOfSize:11.0];
    label_phone.text = @"如有疑问,请拨打我们的客服";
    
    UIButton *button_suggest = [UIButton buttonWithType:UIButtonTypeSystem];
    [button_suggest setTitle:@"反馈" forState:UIControlStateNormal];
    button_suggest.titleLabel.font = [UIFont systemFontOfSize:17 ];//粗体
    button_suggest.tintColor = [UIColor whiteColor];
    [button_suggest addTarget:self action:@selector(button_suggestAction:) forControlEvents:UIControlEventTouchUpInside];
    button_suggest.backgroundColor = REDCOLOR;
    
    
    UIButton *button_serverPhone = [UIButton buttonWithType:UIButtonTypeSystem];
    [button_serverPhone setTitle:@"热线:4001826268" forState:UIControlStateNormal];
    button_serverPhone.titleLabel.font = [UIFont systemFontOfSize:11.0];
    button_serverPhone.titleLabel.adjustsFontSizeToFitWidth = YES;
    button_serverPhone.tintColor = REDCOLOR;
    [button_serverPhone setTitleColor:[UsefulUtil colorWithHexString:@"fb474747"] forState:UIControlStateSelected];
    
    [button_serverPhone addTarget:self action:@selector(button_serverPhoneAction:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view  addSubview:button_serverPhone];
    [self.view addSubview:_field_suggext];
    [self.view addSubview:label_phone];
    [self.view addSubview:button_suggest];
    
    _field_suggext.frame = CGRectMake(MULTIPLYWIDTH(15), MULTIPLYHEIGHT(20), MULTIPLYWIDTH(345), MULTIPLYHEIGHT(180));
    button_suggest.frame = CGRectMake(MULTIPLYWIDTH(30.0 / 2), CGRectGetMaxY(self.field_suggext.frame) + MULTIPLYHEIGHT(62.0 / 2) ,SCREEN_WIDTH - MULTIPLYWIDTH(30.0), MULTIPLYHEIGHT(90.0 / 2));
    label_phone.frame = CGRectMake(0 , CGRectGetMaxY(button_suggest.frame) + MULTIPLYHEIGHT(27), SCREEN_WIDTH, MULTIPLYHEIGHT(10));
    button_serverPhone.frame = CGRectMake(MULTIPLYWIDTH(140), CGRectGetMaxY(label_phone.frame) + MULTIPLYHEIGHT(10), MULTIPLYWIDTH(105), MULTIPLYWIDTH(10));
    
    UIImageView *imageView_phone = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMinX(button_serverPhone.frame) - MULTIPLYWIDTH(5), CGRectGetMinY(button_serverPhone.frame)- MULTIPLYWIDTH(2), MULTIPLYWIDTH(8), MULTIPLYHEIGHT(13))];
    imageView_phone.image = [UIImage imageNamed:@"telephone.png"];
    [self.view addSubview:imageView_phone];
    
    UILabel *label_text = [[UILabel alloc]initWithFrame:CGRectMake(MULTIPLYWIDTH(58.0 / 2), MULTIPLYHEIGHT(40.0 / 2), self.field_suggext.frame.size.width - MULTIPLYWIDTH(58.0), MULTIPLYHEIGHT(90.0 / 2))];
    label_text.text = @"非常感谢您对牛牛的支持,我们期待您的宝贵意见请点击输入......";
    label_text.numberOfLines = 0;
    label_text.font = [UIFont systemFontOfSize:15.0];
    label_text.textColor = [UsefulUtil colorWithHexString:@"#c7c7cd"];
    label_text.tag = 500;
    [self.field_suggext addSubview:label_text];
    
    UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureAction)];
    [self.view addGestureRecognizer:swipeGesture];
    
}
#pragma mark -swipeGestureAction
-(void)swipeGestureAction{
    [self.navigationController popViewControllerAnimated:YES];
    
}
#pragma mark -button_suggestAction
-(void)button_suggestAction:(UITextView *)sender{
    NSLog(@"反馈");
    
    [self.view endEditing:YES]; // keyboard hidden
    
    if ([UserManager sharedUserManager].isAuthentication == YES) {//是否实名认证
        
        if (self.field_suggext.text.length == 0) {
            //内容是否为空
            [UsefulUtil showAlertView:@"反馈内容不能为空"];
            return;
        }else {
            
            [MBProgressHUD showHUDAddedTo:self.view animated:YES];
            
            NSString *contents = self.field_suggext.text;
            
            NSDictionary *dic_feedBack = @{@"token" : GETCURRENTUSERINOBYPRAMETERES(user_userToken) , @"contents" : contents , @"userId" : GETCURRENTUSERINOBYPRAMETERES(user_userId)};
            
            [[NETWorkingUtil sharedNETWorking] zzjrMore_userFeedbackInfoByParmeteres:dic_feedBack transferResultUsingBlock:^(id parsedData, NSError *error) {
                
                [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
                
                if (!error) {
                    
                    NSDictionary *dic_result = parsedData;
                    if ([dic_result[@"status"] integerValue] == 0) {
                        

                        
//                        dispatch_async(dispatch_get_main_queue(), ^{
//                            
//                            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"您的反馈已经收到，非常感谢您的反馈，我们将更加努力为您服务" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
//                            [alertView show];
//                        });
                       [UsefulUtil showAlertView:@"您的反馈已经收到，非常感谢您的反馈，我们将更加努力为您服务"];
                        [self.navigationController popViewControllerAnimated:YES];
                    }else {
                        
                        [UsefulUtil showAlertView:dic_result[@"msg"]];
                        
                    }
                }else {
                    
                    [UsefulUtil showAlertView:@"遇到网络问题,请稍后重试!"];
                }
            }];
        }
    }else {
        //没有实名认证,去实名认证
        IDCardAuthenticationViewController *idVC = [[IDCardAuthenticationViewController alloc]init];
        [self.navigationController pushViewController:idVC animated:YES];
    }
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    
    if (buttonIndex == 0) {
     
        [self.navigationController popViewControllerAnimated:YES];
    }
}

#pragma mark - button_serverPhone
-(void)button_serverPhoneAction:(UIButton*)sender{
    
    NSLog(@"服务热线");
    
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",@"4001826268"];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    
    
}

-(void)textViewDidChange:(UITextView *)textView {
    
    UILabel *label = (UILabel *)[textView viewWithTag:500];
    if (textView.text.length == 0) {
        label.hidden = NO;
    }else {
        label.hidden = YES;
    }
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    //    UITextField *field = (UITextField *)[self.view viewWithTag:400];
    //    [field resignFirstResponder];
    [self.view endEditing:YES];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
